package pe.gob.onpe.tags;


import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.JspFragment;
import javax.servlet.jsp.tagext.SimpleTagSupport;

public class FechaTag extends SimpleTagSupport {

    private String formato = "dd/MM/yyyy";

    /**
     * Called by the container to invoke this tag. 
     * The implementation of this method is provided by the tag library developer,
     * and handles all tag processing, body iteration, etc.
     */
    @Override
    public void doTag() throws JspException {
        JspWriter out = getJspContext().getOut();
        try {
            JspFragment f = getJspBody();
            if (f != null) {
                f.invoke(out);
            }
            SimpleDateFormat df = new SimpleDateFormat(formato);
            out.print(df.format(new Date()));
        } catch (java.io.IOException ex) {
            ex.printStackTrace();
            throw new JspException("Error in FechaTag tag", ex);
        }
    }

    public void setFormato(String formato) {
        this.formato = formato;
    }
}
